package com.inossem.warehousestorage_inossem.request.outStorage;

import android.content.Context;

import com.google.gson.Gson;
import com.inossem.warehousestorage_inossem.bean.outStorage.OutStorageOperatorBean;
import com.inossem.warehousestorage_inossem.constant.Constant;
import com.inossem.warehousestorage_inossem.constant.RequestConstant;
import com.inossem.warehousestorage_inossem.listener.GsonBeanListener;
import com.inossem.warehousestorage_inossem.listener.StringRequestListener;
import com.inossem.warehousestorage_inossem.manage.RequestManage;
import com.inossem.warehousestorage_inossem.model.StringResponse;
import com.inossem.warehousestorage_inossem.request.Request;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by leij on 2017/6/12.
 */

public class OutStorageSelectOperatorRequest extends Request {

    private static final String CONDITION = "condition";//查询条件

    private static final String ROLE_CODE = "role_id";//角色

    public static String request(Context context, String condition, String roleCode, String type, GsonBeanListener gsonBeanListener) {
        String tag;
        Map<String, String> params = new HashMap<>();
        params.put(CONDITION, condition);
        params.put(ROLE_CODE, roleCode);

        String methodUrl = "";
        switch (type) {
            case Constant.SELECT_OPERATOR_TYPE_OUT_STORAGE_PICKING:
                methodUrl = RequestConstant.URL_OUT_STORAGE_PICKING_SELECT_OPERATOR;
                break;
            case Constant.SELECT_OPERATOR_TYPE_OUT_STORAGE_SALE:
                methodUrl = RequestConstant.URL_OUT_STORAGE_SALE_SELECT_OPERATOR;
                break;
            case Constant.SELECT_OPERATOR_TYPE_OUT_STORAGE_RETURN:
                methodUrl = RequestConstant.URL_OUT_STORAGE_RETURN_SELECT_OPERATOR;
                break;
            case Constant.SELECT_OPERATOR_TYPE_OUT_STORAGE_ALLOCATING:
                methodUrl = RequestConstant.URL_OUT_STORAGE_ALLOCATING_SELECT_OPERATOR;
                break;
        }
        String url = RequestManage.getUrl(context, methodUrl + RequestManage.mapEncodeToParams(params));
        tag = RequestManage.getHttpsGetWithLoading(context, url, new StringRequestListener() {
            @Override
            public void onSuccess(StringResponse stringRequestResponse) {
                Gson gson = new Gson();
                OutStorageOperatorBean bean = gson.fromJson(stringRequestResponse.getResponseInfo(), OutStorageOperatorBean.class);
                excuteJsonBean(context, bean, bean.getCode(), bean.getMsg(), gsonBeanListener);
            }
        });
        return tag;
    }

}
